package leetcode.二叉树;

public class 二叉树的最小深度111 {
    public int minDepth(TreeNode root) {
        if(root == null)
            return 0;
        if (root.left == null && root.right == null) {
            return 1;
        }
        int leftDepth = minDepth(root.left);
        int rightDepth = minDepth(root.right);
        if(leftDepth == 0 && rightDepth >0)
            return 1 + rightDepth;
        if(leftDepth > 0 && rightDepth == 0)
            return 1 + leftDepth;
        return 1 + Math.min(leftDepth,rightDepth);

    }
}
